#CC=cc
LD=cc

OS=linux
ARCH=x86

P4_API_DIR=../p4api/$(OS)
DEST=../net.sourceforge.perforce.api.$(OS)
TDIR=bin/$(OS)-$(ARCH)
SDIR=native

INCLUDES=\
	-I$(SDIR)/include\
	-I$(P4_API_DIR)/include/p4\
	-I$(JAVA_HOME)/include\
	-I$(JAVA_HOME)/include/$(OS)

P4_LIBS=\
	$(P4_API_DIR)/lib/libclient.a\
	$(P4_API_DIR)/lib/librpc.a\
	$(P4_API_DIR)/lib/libsupp.a

OBJS=\
	$(TDIR)/ClientApi.o\
	$(TDIR)/ClientMerge.o\
	$(TDIR)/ClientUser.o\
	$(TDIR)/Error.o\
	$(TDIR)/Spec.o\
	$(TDIR)/SpecData.o

TARGET=$(DEST)/os/$(OS)/$(ARCH)/libperforce.so

EXTRA_LIBS=

all: target $(OBJS) lib

$(TDIR)/ClientApi.o: $(SDIR)/ClientApi.cpp
	$(CC) -O3 -fomit-frame-pointer -c $(INCLUDES) $< -o $@

$(TDIR)/ClientMerge.o: $(SDIR)/ClientMerge.cpp
	$(CC) -O3 -fomit-frame-pointer -c $(INCLUDES) $< -o $@

$(TDIR)/ClientUser.o: $(SDIR)/ClientUser.cpp
	$(CC) -O3 -fomit-frame-pointer -c $(INCLUDES) $< -o $@

$(TDIR)/Error.o: $(SDIR)/Error.cpp
	$(CC) -O3 -fomit-frame-pointer -c $(INCLUDES) $< -o $@

$(TDIR)/Spec.o: $(SDIR)/Spec.cpp
	$(CC) -O3 -fomit-frame-pointer -c $(INCLUDES) $< -o $@

$(TDIR)/SpecData.o: $(SDIR)/SpecData.cpp
	$(CC) -O3 -fomit-frame-pointer -c $(INCLUDES) $< -o $@

target:
	mkdir -p $(TDIR)

.cpp.o: 
	$(CC) -O3 -fomit-frame-pointer -c $(INCLUDES) $<

lib: $(TARGET)

$(TARGET):
	$(CC) -shared $(OBJS) $(P4_LIBS) $(EXTRA_LIBS) -o $(TARGET)

clean:
	rm -rf $(OBJS) 

realclean: clean
	rm -rf $(TARGET) 
